Skip to content

Fix getRepoSnapshot tree SHA fallback and remove unconditional branch lookup#167

Merged
naheel0 merged 8 commits into
mainfrom
copilot/fix-code-comments-review-166
May 31, 2026
Merged

Fix getRepoSnapshot tree SHA fallback and remove unconditional branch lookup#167
naheel0 merged 8 commits into
mainfrom
copilot/fix-code-comments-review-166

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 30, 2026

This addresses all unresolved comments in the linked review thread for PR #166. The reported issues were an invalid tree_sha fallback (using commit SHA) and an extra getBranch call on the success path.

  • Tree fetch flow simplified

    • git.getTree now first uses repoInfo.default_branch directly.
    • repos.getBranch is no longer called on every successful repository snapshot request.
  • Fallback now resolves a real tree SHA

    • On initial tree fetch failure, fallback resolves branch.commit.commit.tree.sha.
    • If missing, fallback fetches the commit object via git.getCommit(commit_sha) and uses commit.tree.sha (instead of passing commit SHA to getTree).
  • Failure semantics preserved

    • If fallback resolution cannot produce a tree SHA, the original tree-fetch error is rethrown.
try {
  ({ data: repoTree } = await client.rest.git.getTree({
    owner,
    repo,
    tree_sha: repoInfo.default_branch,
  }));
} catch (initialTreeError) {
  const { data: branch } = await client.rest.repos.getBranch({ owner, repo, branch: repoInfo.default_branch });
  let resolvedTreeSha = getNestedString(branch, ["commit", "commit", "tree", "sha"]);

  if (!resolvedTreeSha) {
    const commitSha = getNestedString(branch, ["commit", "sha"]);
    if (commitSha) {
      const { data: commit } = await client.rest.git.getCommit({ owner, repo, commit_sha: commitSha });
      resolvedTreeSha = commit.tree?.sha;
    }
  }

  if (!resolvedTreeSha) throw initialTreeError;

  ({ data: repoTree } = await client.rest.git.getTree({ owner, repo, tree_sha: resolvedTreeSha }));
}

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
readme-gen-ai Ready Ready Preview, Comment May 31, 2026 7:33am

Copilot AI changed the title [WIP] Fix code based on review comments Fix getRepoSnapshot tree SHA fallback and remove unconditional branch lookup May 30, 2026
Copilot AI requested a review from jaseel0 May 30, 2026 18:28
@naheel0 naheel0 marked this pull request as ready for review May 31, 2026 07:21
@naheel0
Copy link
Copy Markdown
Member

naheel0 commented May 31, 2026

@copilot resolve the merge conflicts in this pull request

@naheel0 naheel0 merged commit 7fbef74 into main May 31, 2026
6 checks passed
@naheel0 naheel0 deleted the copilot/fix-code-comments-review-166 branch May 31, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants